function checkParam(id,code) {
    var json = {};
    //id or code
    if(id){
        json.id = id;
    } else if(code){
        json.code = code;
    }
    $.ajax({
        url: basePath+'current',
        type: 'post',
        dataType: 'json',
        contentType:"application/json",
        data:JSON.stringify(json),
        success: function (back) {
            //暂不放置
        }
    });
}

function getRandomNum() {
    return Math.floor(Math.random()*1000);
}

// 设置选中医院
function setSelectHospital() {
    try {
        console.log("设置选中医院操作");
        var selectHoss = getCheckedRowsByGrid(hosGrid, hosGrid.getColIndexById('select'));
        var currentHos = window.parent.getCurrentHospital();
        if(currentHos == 0){
            return;
        }
        if(!selectHoss||selectHoss[0].id == currentHos){
            // 选中操作
            hosGrid.forEachRow(function(id){
                if(hosGrid.cells(id,hosGrid.getColIndexById('id')).getValue() == currentHos){
                    hosGrid.selectRow(hosGrid.getRowIndex(id),true,true,true);
                    return;
                }
             });
        }
        var index=hosGrid.getRowIndex(hosGrid.getSelectedRowId());
        $('div.objbox').scrollTop($($('.rowselected')[0]).offset().top+((index-22)/2*33+parseInt((index-11)/11)*34-82));
    } catch (e){
        console.log("设置选中医院出错！");
        console.log(e);
        return;
    }
}
//校验日期,为空跳过（格式，str）
function checkDateStr(fmt,value){
    if(!value||value=='') return true;
    //yyyy-MM-dd hh:mm:ss
    var reg=/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)\s+([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/;
    if(fmt=='yyyy-MM-dd hh:mm'){
        reg=/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)\s+([01][0-9]|2[0-3]):[0-5][0-9]$/;
    }
    return reg.test(value);
}

function formatJson (json, options) {
    var reg = null,
        formatted = '',
        pad = 0,
        PADDING = '    ';
    try {
        // optional settings
        options = options || {};
        // remove newline where '{' or '[' follows ':'
        options.newlineAfterColonIfBeforeBraceOrBracket = (options.newlineAfterColonIfBeforeBraceOrBracket === true) ? true : false;
        // use a space after a colon
        options.spaceAfterColon = (options.spaceAfterColon === false) ? false : true;
        // begin formatting...
        if (typeof json !== 'string') {
            // make sure we start with the JSON as a string
            json = JSON.stringify(json);
        } else {
            // is already a string, so parse and re-stringify in order to remove extra whitespace
            json = JSON.parse(json);
            json = JSON.stringify(json);
        }
        // add newline before and after curly braces
        reg = /([\{\}])/g;
        json = json.replace(reg, '\r\n$1\r\n');
        // add newline before and after square brackets
        reg = /([\[\]])/g;
        json = json.replace(reg, '\r\n$1\r\n');
        // add newline after comma
        reg = /(\,)/g;
        json = json.replace(reg, '$1\r\n');
        // remove multiple newlines
        reg = /(\r\n\r\n)/g;
        json = json.replace(reg, '\r\n');
        // remove newlines before commas
        reg = /\r\n\,/g;
        json = json.replace(reg, ',');
        // optional formatting...
        if (!options.newlineAfterColonIfBeforeBraceOrBracket) {
            reg = /\:\r\n\{/g;
            json = json.replace(reg, ':{');
            reg = /\:\r\n\[/g;
            json = json.replace(reg, ':[');
        }
        if (options.spaceAfterColon) {
            reg = /\:/g;
            json = json.replace(reg, ': ');
        }
        $.each(json.split('\r\n'), function (index, node) {
            var i = 0,
                indent = 0,
                padding = '';

            if (node.match(/\{$/) || node.match(/\[$/)) {
                indent = 1;
            } else if (node.match(/\}/) || node.match(/\]/)) {
                if (pad !== 0) {
                    pad -= 1;
                }
            } else {
                indent = 0;
            }
            for (i = 0; i < pad; i++) {
                padding += PADDING;
            }
            formatted += padding + node + '\r\n';
            pad += indent;
        });
    }catch(err){
        //在此处理错误
    }
    return formatted;
};

function format2Json (json, options) {
    var reg = null,
        formatted = '',
        pad = 0,
        PADDING = '    ';
    try {
        // optional settings
        options = options || {};
        // remove newline where '{' or '[' follows ':'
        options.newlineAfterColonIfBeforeBraceOrBracket = (options.newlineAfterColonIfBeforeBraceOrBracket === true) ? true : false;
        // use a space after a colon
        options.spaceAfterColon = (options.spaceAfterColon === false) ? false : true;
        // begin formatting...
        if (typeof json !== 'string') {
            // make sure we start with the JSON as a string
            json = JSON.stringify(json);
        } else {
            // is already a string, so parse and re-stringify in order to remove extra whitespace
            json = JSON.parse(json);
            json = JSON.stringify(json);
        }
        // add newline before and after curly braces
        reg = /([\{])/g;
        // json = json.replace(reg, '\r\n$1\r\n');
        json = json.replace(reg, '<br/>'+'$1'+'<br/>');
        // add newline before and after square brackets
        reg = /([\]])/g;
        json = json.replace(reg, '<br/>'+'$1'+'<br/>');
        reg = /([\[])/g;
        // json = json.replace(reg, '\r\n$1\r\n');
        json = json.replace(reg, '$1'+'<br/>');
        // add newline after comma
        reg = /(\,)/g;
        // json = json.replace(reg, '$1\r\n');
        json = json.replace(reg, '$1'+'<br/>');
        // remove multiple newlines
        reg = /(\r\n\r\n)/g;
        json = json.replace(reg, '\r\n');
        // remove newlines before commas
        reg = /\r\n\,/g;
        // reg = /\r\n\,/g;
        json = json.replace(reg, ',');
        // optional formatting...
        if (!options.newlineAfterColonIfBeforeBraceOrBracket) {
            reg = /\:\r\n\{/g;
            json = json.replace(reg, ':{');
            reg = /\:<br>\[/g;
            json = json.replace(reg, ':[');
        }
        if (options.spaceAfterColon) {
            reg = /\:/g;
            json = json.replace(reg, ': ');
        }
        $.each(json.split('\r\n'), function (index, node) {
            var i = 0,
                indent = 0,
                padding = '';

            if (node.match(/\{$/) || node.match(/\[$/)) {
                indent = 1;
            } else if (node.match(/\}/) || node.match(/\]/)) {
                if (pad !== 0) {
                    pad -= 1;
                }
            } else {
                indent = 0;
            }
            for (i = 0; i < pad; i++) {
                padding += PADDING;
            }
            formatted += padding + node + '\r\n';
            pad += indent;
        });
    }catch(err){
        //在此处理错误
    }
    return formatted;
};